package com.demo.alibaba.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Created by yangshunxing on 2017/2/23.
 */
public class lamda {
    public static void main(String[] args) {
        String[] atp = {"1", "2", "3", "4","5", "6","7", "8"};
        List<String> numbers =  Arrays.asList(atp);

//        numbers.stream().map(n -> new Integer(n)).filter(n -> Prime)

      /*  // 以前的循环方式
        for (String player : players) {
                System.out.print(player + "; ");
            }

        // 使用 lambda 表达式以及函数操作(functional operation)
        players.forEach((player) -> System.out.print(player + "; "));
*/
        // 在 Java 8 中使用双冒号操作符(double colon operator)
//        players.forEach(System.out::println);

        List<Integer> integers = new ArrayList<>();
        integers.add(2);
        integers.add(4);
        integers.add(1);
        integers.add(5);
        integers.add(6);
        integers.add(3);

        List<Integer> integer2 = new ArrayList<>();
        integer2.add(2);
        integer2.add(4);
        integer2.add(1);
        integer2.add(5);
        integer2.add(0);
        integer2.add(3);

        integers.sort((Integer a, Integer b) -> a.compareTo(b));
        integer2.sort((Integer a, Integer b) -> a.compareTo(b));
        integer2.forEach(i -> System.out.println(i));
//        System.out.println(Comparator.comparingInt(integers::get).reversed());
    }
}
